library(shiny)
library(globe4r) 
library(dplyr)

# Read base file
globeindiavax <- readRDS(file = "globeindiavax.rds")

#################
#Interactive plot
##################
create_globe(height = "100vh") %>%
       globe_pov(20.5937, 78.9629) %>% 
  globe_choropleth(
    coords(
      country = admin,
      altitude = Units,
      cap_color = qty
    ), 
    data = globeindiavax
  ) %>% 
    scale_choropleth_cap_color(palette = c("#ffc6c4",
                                           "#f4a3a8",
                                           "#cc607d",
                                           "#ffff66",
                                           "#672044")) %>%  
    scale_choropleth_altitude(0.03, 0.1)

Data source: Ministry of External Affairs, GoI.
Graphic made as part of the 30-day-map-challenge, for day 29 on the theme “globe”.

library(sf)
library(rnaturalearth)
library(rcartocolor)
library(dplyr)
library(extrafont)
library(ggplot2)
#extrafont::loadfonts()

# Get data
vaxexport <- read.csv("vaxexport.csv", header = TRUE, stringsAsFactor = FALSE)
vaxexport <- vaxexport[order(-vaxexport$Units),]

# Units are in lakhs, convert to millions
vaxexport$Units <- vaxexport$Units/10
colnames(vaxexport)[1] <- "admin"

# Create categories
vaxexport$qty <- cut(vaxexport$Units,
                     breaks=c(0, 0.5, 1, 3, Inf), 
                     labels=c("Fewer than 0.5 million",
                              "0.5 to 1 million",
                              "1 to 3 million",
                              "More than 3 million"),
                     include.lowest=TRUE)

# Get globe
crs <- "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +datum=WGS84 +units=m +no_defs"

globe <- ne_countries(scale = 50,
                      type = "countries",
                      returnclass = "sf")
globe <- subset(globe, select = c("iso_a3", "admin"))
globe$flag <- ifelse(globe$admin == "India", 1,
              ifelse(globe$admin %in% vaxexport$admin, 2,
                     3))

# Merge data
globe <- merge(globe, vaxexport, by = "admin", all.x = T)
globe$qty <- ifelse(globe$admin == "India", "India", as.character(globe$qty))

# Globe outline
sphere <- st_graticule(ndiscr = 10000, margin = 10e-6) %>%
  st_transform(crs = crs) %>%
  st_convex_hull() %>%
  summarise(geometry = st_union(geometry))

# Color palette
pal <- carto_pal(7, "Burg")
pal <- pal[c(1,2,4,7)]

############
#Static plot
############
ggplot() +
    geom_sf(data = sphere, fill = "#80bfff", colour = "#80bfff",
            alpha = 0.8) +
    geom_sf(data = globe, colour = "lavenderblush",
            aes(fill=as.factor(qty)), show.legend=TRUE, size=0.5) +
    scale_fill_manual(values=c(pal[1:3], "#ffff66", pal[4]),
                      breaks = c("Fewer than 0.5 million",
                                 "0.5 to 1 million",
                                 "1 to 3 million",
                                 "More than 3 million")) +
    theme_void() +
    theme(plot.margin = margin(5, 0, 10, 0)) +
    labs(fill = "Vaccines sent",
         title= "From India, with love: covid-19 vaccines",
         subtitle= "Over 66 million doses have been exported to 93 countries\nunder Indian government's initiative 'Vaccine Maitri'",
         caption="#30DayMapChallenge | Day 29 | Surbhi Bhatia | Data: Ministry of External Affairs, GoI. Data as of May 19, 2021.") +
    theme(plot.title = element_text(
                                    family = "Impact",
                                    colour = "black",
              size = 20),
      plot.subtitle = element_text(size = 14),  
          plot.caption = element_text(size = 10),
          legend.title = element_text(color = "black",
                                      size = 19),
          legend.text = element_text(color = "black",
                                      size = 12),
          plot.background = element_rect(color = NA))